﻿using DFGK_WMS.IRepository;
using DFGK_WMS.Model.DTO;
using DFGK_WMS.Model.Models;
using DFGK_WMS.Repository;
using DFGK_WMS.WebAPI.Controllers.Result;
using DFGK_WMS.WebAPI.Tools;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace DFGK_WMS.WebAPI.Controllers.数字孪生
{
    /// <summary>
    /// 输送线设备
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class TPipeLineController : ControllerBase
    {
        private readonly WebSocketConnectManager socketManager;
        public TPipeLineController(WebSocketConnectManager socketConnectManager)
        {
            socketManager = socketConnectManager;
        }
        /// <summary>
        /// 添加输送线设备信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IActionResult AddTPipeLine(TPipeLine line)
        {
            socketManager.SendMsgToAllClients(JsonConvert.SerializeObject(new {type=2,data=line}));
            return Ok(BaseResult.ReturnInfo(0, "", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
        }
        /// <summary>
        /// 输送线任务完成或故障上报
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult PipeLineApper(LineDto dto)
        {
            socketManager.SendMsgToAllClients(JsonConvert.SerializeObject(new {type=3,data=dto}));
            return Ok(BaseResult.ReturnInfo(0, "", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
        }
    }
}
